using System.Collections.Generic;
using System.Linq;
using Olemas.Models;

namespace Olemas.DataModels
{
    public class FacultyModel
    {
        /// <summary>
        /// Gets the Id of the faculty by name.
        /// </summary>
        /// <param name="name">The Name of the faculty.</param>
        public static int GetFacultyId(string name)
        {
            var db = new OlemasDatabaseEntities();
            var facultyId = 0;
            var faculty = (from fac in db.Faculties
                           where fac.Name == name
                           select fac).SingleOrDefault();

            if (faculty != null)
            {
                facultyId = faculty.Id;

            }
            return facultyId;

        }
        /// <summary>
        /// Gets all the faculties from the db.
        /// </summary>
        public static IQueryable<Faculty> GetOrderedFaculties()
        {
            var db = new OlemasDatabaseEntities();
            return db.Faculties.OrderBy(n => n.Name);
        }
    }
}